package org.example.food.service.impl;

import cn.hutool.crypto.digest.DigestUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.IService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.example.food.mapper.AccountMapper;
import org.example.food.pojo.User;
import org.example.food.service.AccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Objects;

@Service
@Transactional
public class AccountServiceImpl extends ServiceImpl<AccountMapper,User> implements AccountService {
    @Autowired
    private AccountMapper accountMapper;
    @Override
    public boolean login(String userName, String userPwd) {
        //去数据库查询
        QueryWrapper<User> qw=new QueryWrapper<>();
        qw.eq("username",userName);
        User user = accountMapper.selectOne(qw);
        //判断是否有该对象
        if (user==null){
            return false;
        }

        //加密密码
        String s = DigestUtil.md5Hex(userPwd);
        //有则判断密码是否正确
        if (s.equals(user.getPassword())){
            return true;
        }else {
            return false;
        }
    }
}
